﻿using System;
using System.Collections.Generic;
using System.Text;

namespace T.FAS.Runtime.Metadata.Plugin
{
    public class ColorTool
    {
        private Random _random = new Random();

        // 获取不相近颜色的方法
        public Colors GetUnrelatedColor()
        {
            // 每组的第 1 个颜色（如 BlueLight2, CyanLight2 等）
            Colors[] group0 = ColorPalette[0];
            // 从组 0 中随机选择一个颜色
            return group0[_random.Next(group0.Length)];
        }

        // 获取一组不相近颜色
        public Colors[] GetUnrelatedColors(int count)
        {
            Colors[] result = new Colors[count];
            var usedGroups = new bool[ColorPalette.Length];

            for (int i = 0; i < count; i++)
            {
                // 随机选择一组（避免连续从同一组中选择）
                int groupIndex;
                do
                {
                    groupIndex = _random.Next(ColorPalette.Length);
                } while (usedGroups[groupIndex] && i > 0);

                usedGroups[groupIndex] = true;

                // 从选择的组中随机获取一个颜色
                Colors[] group = ColorPalette[groupIndex];
                result[i] = group[_random.Next(group.Length)];
            }

            return result;
        }
        public static Colors[][] GenerateColorPalette()
        {
            Colors[] colors = (Colors[])Enum.GetValues(typeof(Colors));
            int colorCount = colors.Length;
            int groupCount = 5;
            Colors[][] result = new Colors[groupCount][];

            for (int i = 0; i < colorCount; i++)
            {
                int groupIndex = i % groupCount;
                int indexInGroup = i / groupCount;

                if (result[groupIndex] == null)
                    result[groupIndex] = new Colors[indexInGroup + 1];
                else
                    Array.Resize(ref result[groupIndex], indexInGroup + 1);

                result[groupIndex][indexInGroup] = colors[i];
            }

            return result;
        }

        public static Colors[][] ColorPalette = GenerateColorPalette();
    }
    public enum Colors
    {
        blueLight2, blueLight1, blueBright, blue, blueDark1,
        cyanLight2, cyanLight1, cyanBright, cyan, cyanDark1,
        grayLight2, grayLight1, grayBright, gray, grayDark1,
        greenLight2, greenLight1, greenBright, green, greenDark1,
        orangeLight2, orangeLight1, orangeBright, orange, orangeDark1,
        pinkLight2, pinkLight1, pinkBright, pink, pinkDark1,
        purpleLight2, purpleLight1, purpleBright, purple, purpleDark1,
        redLight2, redLight1, redBright, red, redDark1,
        tealLight2, tealLight1, tealBright, teal, tealDark1,
        yellowLight2, yellowLight1, yellowBright, yellow, yellowDark1
    }

    
}
